package com.woniu.controller;



import com.fasterxml.jackson.annotation.JsonFormat;
import com.woniu.pojo.Users;
import com.woniu.service.HomeService;
import com.woniu.service.UsersService;
import com.woniu.userLog.LogPoint;
import com.woniu.util.UploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Api(tags = "个人资料")
@Controller
@RequestMapping("/person")
@CrossOrigin(allowCredentials="true",maxAge = 3600)
public class PersonController {

    @Autowired
    UsersService usersService;

    @Autowired
    HomeService homeService;


    /*
     *  @auth:米雷
     *  查询用户的详细信息，
     *
     *
     **/
    @ApiOperation(value = "个人信息")
    @GetMapping("/getPerson")
    @ResponseBody
    @LogPoint("用户查看个人信息")
    public Users Personal(long id)
    {
        Users user = usersService.getUser(id);
        return user;
    }

    /*
     *  @auth:米雷
     *  修改用户的基础信息，不包括房屋
     *
     **/
    @PostMapping("/updatePerson")
    @ResponseBody
    @ApiOperation(value = "修改个人信息")
    @LogPoint("用户修改个人信息")
    public String updatePerson(Integer id, String userName, String birthday, String birthPlace, String phoneNumber,String headimg)
    {
        System.out.println(id+userName+birthday+birthPlace+phoneNumber+"+++++++++++++++++++++");
        String result = usersService.updateByOther(id,userName,birthday,birthPlace,phoneNumber,headimg);
        return result;
    }



    /*
    *
    *  修改密码
    * */
    @RequestMapping("/updatePass")
    @ResponseBody
    @ApiOperation(value = "修改密码")
    @LogPoint("用户修改密码")
    public String updatePass(@RequestParam("oldPass") String oldPass,
                             @RequestParam("newPass")String newPass,
                             @RequestParam("id")Long id){
        String old =usersService.getOldPass(id);

        if (old.equals(oldPass)){
            return "密码不符";
        }else {
            int update=usersService.updatePass(id,newPass,oldPass);
            if (update!=0){
                return "修改成功";
            }else {
                return "修改失败";
            }
        }
    }



    /* *//*
     *  @auth:米雷
     *  查看收货地址
     *
     **//*
    @GetMapping("/getRecAddress")
    @ResponseBody
    public List<Shipping> getRecAddress(Long id){
        List<Shipping> shippings=usersService.getRecAddress(id);
        return shippings;
    }*/
    /*
     *//*
     *  @auth:米雷
     *  删除收货地址
     *
     **//*
    @DeleteMapping("/deleteRecAddress")
    @ResponseBody
    public String delRecAddress(int id){
        String result= usersService.delRecAddress(id);
        return result;
    }

    *//*
     *  @auth:米雷
     *  修改收货地址
     *
     **//*
    @PostMapping("/postRecAddress")
    @ResponseBody
    public String upateRecAd(Shipping shipping){
        String res=usersService.updateRecAddress(shipping);
        return res;
    }*/
}
